{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from cot import Collection\n",
    "from cot.stats import evaluation_as_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[nltk_data] Downloading package punkt to /home/kon/nltk_data...\n",
      "[nltk_data]   Package punkt is already up-to-date!\n"
     ]
    }
   ],
   "source": [
    "ts = Collection.load_thoughtsource_100()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/kon/work/ThoughtSource/libs/cot/cot/stats.py:406: PerformanceWarning: indexing past lexsort depth may impact performance.\n",
      "  df.loc[dataset, (instruction + \"_\" + cot_trigger, model)] = v\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_88af4_row0_col1, #T_88af4_row1_col19, #T_88af4_row2_col19, #T_88af4_row3_col19, #T_88af4_row4_col19, #T_88af4_row5_col3, #T_88af4_row6_col19 {\n",
       "  font-weight: bold;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_88af4\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th id=\"T_88af4_level0_col0\" class=\"col_heading level0 col0\" colspan=\"6\">None_None</th>\n",
       "      <th id=\"T_88af4_level0_col6\" class=\"col_heading level0 col6\" colspan=\"5\">None_kojima-01</th>\n",
       "      <th id=\"T_88af4_level0_col11\" class=\"col_heading level0 col11\" >None_kojima-03</th>\n",
       "      <th id=\"T_88af4_level0_col12\" class=\"col_heading level0 col12\" >None_kojima-09</th>\n",
       "      <th id=\"T_88af4_level0_col13\" class=\"col_heading level0 col13\" >None_lievin-01</th>\n",
       "      <th id=\"T_88af4_level0_col14\" class=\"col_heading level0 col14\" >None_lievin-02</th>\n",
       "      <th id=\"T_88af4_level0_col15\" class=\"col_heading level0 col15\" >None_lievin-03</th>\n",
       "      <th id=\"T_88af4_level0_col16\" class=\"col_heading level0 col16\" >None_lievin-10</th>\n",
       "      <th id=\"T_88af4_level0_col17\" class=\"col_heading level0 col17\" colspan=\"3\">None_zhou-01</th>\n",
       "      <th id=\"T_88af4_level0_col20\" class=\"col_heading level0 col20\" >qa-01_None</th>\n",
       "      <th id=\"T_88af4_level0_col21\" class=\"col_heading level0 col21\" >qa-05_None</th>\n",
       "      <th id=\"T_88af4_level0_col22\" class=\"col_heading level0 col22\" >qa-08_None</th>\n",
       "      <th id=\"T_88af4_level0_col23\" class=\"col_heading level0 col23\" >qa-09_None</th>\n",
       "      <th id=\"T_88af4_level0_col24\" class=\"col_heading level0 col24\" >qa-10_None</th>\n",
       "      <th id=\"T_88af4_level0_col25\" class=\"col_heading level0 col25\" >qa-12_None</th>\n",
       "      <th id=\"T_88af4_level0_col26\" class=\"col_heading level0 col26\" >qa-13_None</th>\n",
       "      <th id=\"T_88af4_level0_col27\" class=\"col_heading level0 col27\" >qa-16_None</th>\n",
       "      <th id=\"T_88af4_level0_col28\" class=\"col_heading level0 col28\" >qa-17_None</th>\n",
       "      <th id=\"T_88af4_level0_col29\" class=\"col_heading level0 col29\" >zhou-01-ins_None</th>\n",
       "      <th id=\"T_88af4_level0_col30\" class=\"col_heading level0 col30\" >zhou-01-ins_zhou-01</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th class=\"blank level1\" >&nbsp;</th>\n",
       "      <th id=\"T_88af4_level1_col0\" class=\"col_heading level1 col0\" >command-xlarge-nightly</th>\n",
       "      <th id=\"T_88af4_level1_col1\" class=\"col_heading level1 col1\" >flan-T5-xxl</th>\n",
       "      <th id=\"T_88af4_level1_col2\" class=\"col_heading level1 col2\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col3\" class=\"col_heading level1 col3\" >gpt-4</th>\n",
       "      <th id=\"T_88af4_level1_col4\" class=\"col_heading level1 col4\" >text-davinci-002</th>\n",
       "      <th id=\"T_88af4_level1_col5\" class=\"col_heading level1 col5\" >text-davinci-003</th>\n",
       "      <th id=\"T_88af4_level1_col6\" class=\"col_heading level1 col6\" >command-xlarge-nightly</th>\n",
       "      <th id=\"T_88af4_level1_col7\" class=\"col_heading level1 col7\" >flan-T5-xxl</th>\n",
       "      <th id=\"T_88af4_level1_col8\" class=\"col_heading level1 col8\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col9\" class=\"col_heading level1 col9\" >text-davinci-002</th>\n",
       "      <th id=\"T_88af4_level1_col10\" class=\"col_heading level1 col10\" >text-davinci-003</th>\n",
       "      <th id=\"T_88af4_level1_col11\" class=\"col_heading level1 col11\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col12\" class=\"col_heading level1 col12\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col13\" class=\"col_heading level1 col13\" >text-davinci-002</th>\n",
       "      <th id=\"T_88af4_level1_col14\" class=\"col_heading level1 col14\" >text-davinci-002</th>\n",
       "      <th id=\"T_88af4_level1_col15\" class=\"col_heading level1 col15\" >text-davinci-002</th>\n",
       "      <th id=\"T_88af4_level1_col16\" class=\"col_heading level1 col16\" >text-davinci-002</th>\n",
       "      <th id=\"T_88af4_level1_col17\" class=\"col_heading level1 col17\" >flan-T5-xxl</th>\n",
       "      <th id=\"T_88af4_level1_col18\" class=\"col_heading level1 col18\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col19\" class=\"col_heading level1 col19\" >gpt-4</th>\n",
       "      <th id=\"T_88af4_level1_col20\" class=\"col_heading level1 col20\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col21\" class=\"col_heading level1 col21\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col22\" class=\"col_heading level1 col22\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col23\" class=\"col_heading level1 col23\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col24\" class=\"col_heading level1 col24\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col25\" class=\"col_heading level1 col25\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col26\" class=\"col_heading level1 col26\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col27\" class=\"col_heading level1 col27\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col28\" class=\"col_heading level1 col28\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col29\" class=\"col_heading level1 col29\" >gpt-3.5-turbo</th>\n",
       "      <th id=\"T_88af4_level1_col30\" class=\"col_heading level1 col30\" >gpt-3.5-turbo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_88af4_level0_row0\" class=\"row_heading level0 row0\" >commonsense_qa</th>\n",
       "      <td id=\"T_88af4_row0_col0\" class=\"data row0 col0\" >0.51</td>\n",
       "      <td id=\"T_88af4_row0_col1\" class=\"data row0 col1\" >0.87</td>\n",
       "      <td id=\"T_88af4_row0_col2\" class=\"data row0 col2\" >0.72</td>\n",
       "      <td id=\"T_88af4_row0_col3\" class=\"data row0 col3\" >0.75</td>\n",
       "      <td id=\"T_88af4_row0_col4\" class=\"data row0 col4\" >0.69</td>\n",
       "      <td id=\"T_88af4_row0_col5\" class=\"data row0 col5\" >0.72</td>\n",
       "      <td id=\"T_88af4_row0_col6\" class=\"data row0 col6\" >0.53</td>\n",
       "      <td id=\"T_88af4_row0_col7\" class=\"data row0 col7\" >0.81</td>\n",
       "      <td id=\"T_88af4_row0_col8\" class=\"data row0 col8\" >0.67</td>\n",
       "      <td id=\"T_88af4_row0_col9\" class=\"data row0 col9\" >0.66</td>\n",
       "      <td id=\"T_88af4_row0_col10\" class=\"data row0 col10\" >0.65</td>\n",
       "      <td id=\"T_88af4_row0_col11\" class=\"data row0 col11\" >0.63</td>\n",
       "      <td id=\"T_88af4_row0_col12\" class=\"data row0 col12\" >0.70</td>\n",
       "      <td id=\"T_88af4_row0_col13\" class=\"data row0 col13\" >nan</td>\n",
       "      <td id=\"T_88af4_row0_col14\" class=\"data row0 col14\" >nan</td>\n",
       "      <td id=\"T_88af4_row0_col15\" class=\"data row0 col15\" >nan</td>\n",
       "      <td id=\"T_88af4_row0_col16\" class=\"data row0 col16\" >nan</td>\n",
       "      <td id=\"T_88af4_row0_col17\" class=\"data row0 col17\" >0.83</td>\n",
       "      <td id=\"T_88af4_row0_col18\" class=\"data row0 col18\" >0.66</td>\n",
       "      <td id=\"T_88af4_row0_col19\" class=\"data row0 col19\" >0.72</td>\n",
       "      <td id=\"T_88af4_row0_col20\" class=\"data row0 col20\" >0.66</td>\n",
       "      <td id=\"T_88af4_row0_col21\" class=\"data row0 col21\" >0.69</td>\n",
       "      <td id=\"T_88af4_row0_col22\" class=\"data row0 col22\" >0.62</td>\n",
       "      <td id=\"T_88af4_row0_col23\" class=\"data row0 col23\" >0.64</td>\n",
       "      <td id=\"T_88af4_row0_col24\" class=\"data row0 col24\" >0.68</td>\n",
       "      <td id=\"T_88af4_row0_col25\" class=\"data row0 col25\" >0.63</td>\n",
       "      <td id=\"T_88af4_row0_col26\" class=\"data row0 col26\" >0.61</td>\n",
       "      <td id=\"T_88af4_row0_col27\" class=\"data row0 col27\" >0.58</td>\n",
       "      <td id=\"T_88af4_row0_col28\" class=\"data row0 col28\" >0.66</td>\n",
       "      <td id=\"T_88af4_row0_col29\" class=\"data row0 col29\" >0.72</td>\n",
       "      <td id=\"T_88af4_row0_col30\" class=\"data row0 col30\" >0.65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_88af4_level0_row1\" class=\"row_heading level0 row1\" >med_qa</th>\n",
       "      <td id=\"T_88af4_row1_col0\" class=\"data row1 col0\" >0.23</td>\n",
       "      <td id=\"T_88af4_row1_col1\" class=\"data row1 col1\" >0.32</td>\n",
       "      <td id=\"T_88af4_row1_col2\" class=\"data row1 col2\" >0.58</td>\n",
       "      <td id=\"T_88af4_row1_col3\" class=\"data row1 col3\" >0.73</td>\n",
       "      <td id=\"T_88af4_row1_col4\" class=\"data row1 col4\" >0.41</td>\n",
       "      <td id=\"T_88af4_row1_col5\" class=\"data row1 col5\" >0.43</td>\n",
       "      <td id=\"T_88af4_row1_col6\" class=\"data row1 col6\" >0.31</td>\n",
       "      <td id=\"T_88af4_row1_col7\" class=\"data row1 col7\" >0.34</td>\n",
       "      <td id=\"T_88af4_row1_col8\" class=\"data row1 col8\" >0.59</td>\n",
       "      <td id=\"T_88af4_row1_col9\" class=\"data row1 col9\" >0.34</td>\n",
       "      <td id=\"T_88af4_row1_col10\" class=\"data row1 col10\" >0.43</td>\n",
       "      <td id=\"T_88af4_row1_col11\" class=\"data row1 col11\" >0.59</td>\n",
       "      <td id=\"T_88af4_row1_col12\" class=\"data row1 col12\" >0.51</td>\n",
       "      <td id=\"T_88af4_row1_col13\" class=\"data row1 col13\" >0.44</td>\n",
       "      <td id=\"T_88af4_row1_col14\" class=\"data row1 col14\" >0.50</td>\n",
       "      <td id=\"T_88af4_row1_col15\" class=\"data row1 col15\" >0.49</td>\n",
       "      <td id=\"T_88af4_row1_col16\" class=\"data row1 col16\" >0.45</td>\n",
       "      <td id=\"T_88af4_row1_col17\" class=\"data row1 col17\" >0.27</td>\n",
       "      <td id=\"T_88af4_row1_col18\" class=\"data row1 col18\" >0.65</td>\n",
       "      <td id=\"T_88af4_row1_col19\" class=\"data row1 col19\" >0.76</td>\n",
       "      <td id=\"T_88af4_row1_col20\" class=\"data row1 col20\" >0.54</td>\n",
       "      <td id=\"T_88af4_row1_col21\" class=\"data row1 col21\" >0.53</td>\n",
       "      <td id=\"T_88af4_row1_col22\" class=\"data row1 col22\" >0.46</td>\n",
       "      <td id=\"T_88af4_row1_col23\" class=\"data row1 col23\" >0.55</td>\n",
       "      <td id=\"T_88af4_row1_col24\" class=\"data row1 col24\" >0.56</td>\n",
       "      <td id=\"T_88af4_row1_col25\" class=\"data row1 col25\" >0.59</td>\n",
       "      <td id=\"T_88af4_row1_col26\" class=\"data row1 col26\" >0.49</td>\n",
       "      <td id=\"T_88af4_row1_col27\" class=\"data row1 col27\" >0.60</td>\n",
       "      <td id=\"T_88af4_row1_col28\" class=\"data row1 col28\" >0.56</td>\n",
       "      <td id=\"T_88af4_row1_col29\" class=\"data row1 col29\" >0.54</td>\n",
       "      <td id=\"T_88af4_row1_col30\" class=\"data row1 col30\" >0.52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_88af4_level0_row2\" class=\"row_heading level0 row2\" >medmc_qa</th>\n",
       "      <td id=\"T_88af4_row2_col0\" class=\"data row2 col0\" >0.25</td>\n",
       "      <td id=\"T_88af4_row2_col1\" class=\"data row2 col1\" >0.34</td>\n",
       "      <td id=\"T_88af4_row2_col2\" class=\"data row2 col2\" >0.58</td>\n",
       "      <td id=\"T_88af4_row2_col3\" class=\"data row2 col3\" >0.69</td>\n",
       "      <td id=\"T_88af4_row2_col4\" class=\"data row2 col4\" >0.34</td>\n",
       "      <td id=\"T_88af4_row2_col5\" class=\"data row2 col5\" >0.40</td>\n",
       "      <td id=\"T_88af4_row2_col6\" class=\"data row2 col6\" >0.22</td>\n",
       "      <td id=\"T_88af4_row2_col7\" class=\"data row2 col7\" >0.35</td>\n",
       "      <td id=\"T_88af4_row2_col8\" class=\"data row2 col8\" >0.47</td>\n",
       "      <td id=\"T_88af4_row2_col9\" class=\"data row2 col9\" >0.36</td>\n",
       "      <td id=\"T_88af4_row2_col10\" class=\"data row2 col10\" >0.36</td>\n",
       "      <td id=\"T_88af4_row2_col11\" class=\"data row2 col11\" >0.50</td>\n",
       "      <td id=\"T_88af4_row2_col12\" class=\"data row2 col12\" >0.50</td>\n",
       "      <td id=\"T_88af4_row2_col13\" class=\"data row2 col13\" >0.45</td>\n",
       "      <td id=\"T_88af4_row2_col14\" class=\"data row2 col14\" >0.41</td>\n",
       "      <td id=\"T_88af4_row2_col15\" class=\"data row2 col15\" >0.40</td>\n",
       "      <td id=\"T_88af4_row2_col16\" class=\"data row2 col16\" >0.42</td>\n",
       "      <td id=\"T_88af4_row2_col17\" class=\"data row2 col17\" >0.31</td>\n",
       "      <td id=\"T_88af4_row2_col18\" class=\"data row2 col18\" >0.48</td>\n",
       "      <td id=\"T_88af4_row2_col19\" class=\"data row2 col19\" >0.70</td>\n",
       "      <td id=\"T_88af4_row2_col20\" class=\"data row2 col20\" >0.47</td>\n",
       "      <td id=\"T_88af4_row2_col21\" class=\"data row2 col21\" >0.42</td>\n",
       "      <td id=\"T_88af4_row2_col22\" class=\"data row2 col22\" >0.45</td>\n",
       "      <td id=\"T_88af4_row2_col23\" class=\"data row2 col23\" >0.47</td>\n",
       "      <td id=\"T_88af4_row2_col24\" class=\"data row2 col24\" >0.49</td>\n",
       "      <td id=\"T_88af4_row2_col25\" class=\"data row2 col25\" >0.53</td>\n",
       "      <td id=\"T_88af4_row2_col26\" class=\"data row2 col26\" >0.41</td>\n",
       "      <td id=\"T_88af4_row2_col27\" class=\"data row2 col27\" >0.48</td>\n",
       "      <td id=\"T_88af4_row2_col28\" class=\"data row2 col28\" >0.53</td>\n",
       "      <td id=\"T_88af4_row2_col29\" class=\"data row2 col29\" >0.44</td>\n",
       "      <td id=\"T_88af4_row2_col30\" class=\"data row2 col30\" >0.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_88af4_level0_row3\" class=\"row_heading level0 row3\" >open_book_qa</th>\n",
       "      <td id=\"T_88af4_row3_col0\" class=\"data row3 col0\" >0.59</td>\n",
       "      <td id=\"T_88af4_row3_col1\" class=\"data row3 col1\" >0.82</td>\n",
       "      <td id=\"T_88af4_row3_col2\" class=\"data row3 col2\" >0.77</td>\n",
       "      <td id=\"T_88af4_row3_col3\" class=\"data row3 col3\" >0.92</td>\n",
       "      <td id=\"T_88af4_row3_col4\" class=\"data row3 col4\" >0.67</td>\n",
       "      <td id=\"T_88af4_row3_col5\" class=\"data row3 col5\" >0.70</td>\n",
       "      <td id=\"T_88af4_row3_col6\" class=\"data row3 col6\" >0.38</td>\n",
       "      <td id=\"T_88af4_row3_col7\" class=\"data row3 col7\" >0.79</td>\n",
       "      <td id=\"T_88af4_row3_col8\" class=\"data row3 col8\" >0.77</td>\n",
       "      <td id=\"T_88af4_row3_col9\" class=\"data row3 col9\" >0.57</td>\n",
       "      <td id=\"T_88af4_row3_col10\" class=\"data row3 col10\" >0.67</td>\n",
       "      <td id=\"T_88af4_row3_col11\" class=\"data row3 col11\" >0.73</td>\n",
       "      <td id=\"T_88af4_row3_col12\" class=\"data row3 col12\" >0.73</td>\n",
       "      <td id=\"T_88af4_row3_col13\" class=\"data row3 col13\" >nan</td>\n",
       "      <td id=\"T_88af4_row3_col14\" class=\"data row3 col14\" >nan</td>\n",
       "      <td id=\"T_88af4_row3_col15\" class=\"data row3 col15\" >nan</td>\n",
       "      <td id=\"T_88af4_row3_col16\" class=\"data row3 col16\" >nan</td>\n",
       "      <td id=\"T_88af4_row3_col17\" class=\"data row3 col17\" >0.81</td>\n",
       "      <td id=\"T_88af4_row3_col18\" class=\"data row3 col18\" >0.81</td>\n",
       "      <td id=\"T_88af4_row3_col19\" class=\"data row3 col19\" >0.95</td>\n",
       "      <td id=\"T_88af4_row3_col20\" class=\"data row3 col20\" >0.73</td>\n",
       "      <td id=\"T_88af4_row3_col21\" class=\"data row3 col21\" >0.65</td>\n",
       "      <td id=\"T_88af4_row3_col22\" class=\"data row3 col22\" >0.73</td>\n",
       "      <td id=\"T_88af4_row3_col23\" class=\"data row3 col23\" >0.71</td>\n",
       "      <td id=\"T_88af4_row3_col24\" class=\"data row3 col24\" >0.73</td>\n",
       "      <td id=\"T_88af4_row3_col25\" class=\"data row3 col25\" >0.80</td>\n",
       "      <td id=\"T_88af4_row3_col26\" class=\"data row3 col26\" >0.72</td>\n",
       "      <td id=\"T_88af4_row3_col27\" class=\"data row3 col27\" >0.69</td>\n",
       "      <td id=\"T_88af4_row3_col28\" class=\"data row3 col28\" >0.69</td>\n",
       "      <td id=\"T_88af4_row3_col29\" class=\"data row3 col29\" >0.76</td>\n",
       "      <td id=\"T_88af4_row3_col30\" class=\"data row3 col30\" >0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_88af4_level0_row4\" class=\"row_heading level0 row4\" >strategy_qa</th>\n",
       "      <td id=\"T_88af4_row4_col0\" class=\"data row4 col0\" >0.52</td>\n",
       "      <td id=\"T_88af4_row4_col1\" class=\"data row4 col1\" >0.61</td>\n",
       "      <td id=\"T_88af4_row4_col2\" class=\"data row4 col2\" >0.57</td>\n",
       "      <td id=\"T_88af4_row4_col3\" class=\"data row4 col3\" >0.71</td>\n",
       "      <td id=\"T_88af4_row4_col4\" class=\"data row4 col4\" >0.59</td>\n",
       "      <td id=\"T_88af4_row4_col5\" class=\"data row4 col5\" >0.53</td>\n",
       "      <td id=\"T_88af4_row4_col6\" class=\"data row4 col6\" >0.59</td>\n",
       "      <td id=\"T_88af4_row4_col7\" class=\"data row4 col7\" >0.69</td>\n",
       "      <td id=\"T_88af4_row4_col8\" class=\"data row4 col8\" >0.56</td>\n",
       "      <td id=\"T_88af4_row4_col9\" class=\"data row4 col9\" >0.46</td>\n",
       "      <td id=\"T_88af4_row4_col10\" class=\"data row4 col10\" >0.54</td>\n",
       "      <td id=\"T_88af4_row4_col11\" class=\"data row4 col11\" >0.52</td>\n",
       "      <td id=\"T_88af4_row4_col12\" class=\"data row4 col12\" >0.58</td>\n",
       "      <td id=\"T_88af4_row4_col13\" class=\"data row4 col13\" >nan</td>\n",
       "      <td id=\"T_88af4_row4_col14\" class=\"data row4 col14\" >nan</td>\n",
       "      <td id=\"T_88af4_row4_col15\" class=\"data row4 col15\" >nan</td>\n",
       "      <td id=\"T_88af4_row4_col16\" class=\"data row4 col16\" >nan</td>\n",
       "      <td id=\"T_88af4_row4_col17\" class=\"data row4 col17\" >0.59</td>\n",
       "      <td id=\"T_88af4_row4_col18\" class=\"data row4 col18\" >0.59</td>\n",
       "      <td id=\"T_88af4_row4_col19\" class=\"data row4 col19\" >0.80</td>\n",
       "      <td id=\"T_88af4_row4_col20\" class=\"data row4 col20\" >0.44</td>\n",
       "      <td id=\"T_88af4_row4_col21\" class=\"data row4 col21\" >0.43</td>\n",
       "      <td id=\"T_88af4_row4_col22\" class=\"data row4 col22\" >0.58</td>\n",
       "      <td id=\"T_88af4_row4_col23\" class=\"data row4 col23\" >0.62</td>\n",
       "      <td id=\"T_88af4_row4_col24\" class=\"data row4 col24\" >0.56</td>\n",
       "      <td id=\"T_88af4_row4_col25\" class=\"data row4 col25\" >0.50</td>\n",
       "      <td id=\"T_88af4_row4_col26\" class=\"data row4 col26\" >0.64</td>\n",
       "      <td id=\"T_88af4_row4_col27\" class=\"data row4 col27\" >0.63</td>\n",
       "      <td id=\"T_88af4_row4_col28\" class=\"data row4 col28\" >0.58</td>\n",
       "      <td id=\"T_88af4_row4_col29\" class=\"data row4 col29\" >0.52</td>\n",
       "      <td id=\"T_88af4_row4_col30\" class=\"data row4 col30\" >0.57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_88af4_level0_row5\" class=\"row_heading level0 row5\" >worldtree</th>\n",
       "      <td id=\"T_88af4_row5_col0\" class=\"data row5 col0\" >0.63</td>\n",
       "      <td id=\"T_88af4_row5_col1\" class=\"data row5 col1\" >0.85</td>\n",
       "      <td id=\"T_88af4_row5_col2\" class=\"data row5 col2\" >0.96</td>\n",
       "      <td id=\"T_88af4_row5_col3\" class=\"data row5 col3\" >0.99</td>\n",
       "      <td id=\"T_88af4_row5_col4\" class=\"data row5 col4\" >0.88</td>\n",
       "      <td id=\"T_88af4_row5_col5\" class=\"data row5 col5\" >0.91</td>\n",
       "      <td id=\"T_88af4_row5_col6\" class=\"data row5 col6\" >0.58</td>\n",
       "      <td id=\"T_88af4_row5_col7\" class=\"data row5 col7\" >0.80</td>\n",
       "      <td id=\"T_88af4_row5_col8\" class=\"data row5 col8\" >0.93</td>\n",
       "      <td id=\"T_88af4_row5_col9\" class=\"data row5 col9\" >0.78</td>\n",
       "      <td id=\"T_88af4_row5_col10\" class=\"data row5 col10\" >0.89</td>\n",
       "      <td id=\"T_88af4_row5_col11\" class=\"data row5 col11\" >0.95</td>\n",
       "      <td id=\"T_88af4_row5_col12\" class=\"data row5 col12\" >0.95</td>\n",
       "      <td id=\"T_88af4_row5_col13\" class=\"data row5 col13\" >nan</td>\n",
       "      <td id=\"T_88af4_row5_col14\" class=\"data row5 col14\" >nan</td>\n",
       "      <td id=\"T_88af4_row5_col15\" class=\"data row5 col15\" >nan</td>\n",
       "      <td id=\"T_88af4_row5_col16\" class=\"data row5 col16\" >nan</td>\n",
       "      <td id=\"T_88af4_row5_col17\" class=\"data row5 col17\" >0.83</td>\n",
       "      <td id=\"T_88af4_row5_col18\" class=\"data row5 col18\" >0.92</td>\n",
       "      <td id=\"T_88af4_row5_col19\" class=\"data row5 col19\" >0.99</td>\n",
       "      <td id=\"T_88af4_row5_col20\" class=\"data row5 col20\" >0.95</td>\n",
       "      <td id=\"T_88af4_row5_col21\" class=\"data row5 col21\" >0.74</td>\n",
       "      <td id=\"T_88af4_row5_col22\" class=\"data row5 col22\" >0.92</td>\n",
       "      <td id=\"T_88af4_row5_col23\" class=\"data row5 col23\" >0.91</td>\n",
       "      <td id=\"T_88af4_row5_col24\" class=\"data row5 col24\" >0.95</td>\n",
       "      <td id=\"T_88af4_row5_col25\" class=\"data row5 col25\" >0.92</td>\n",
       "      <td id=\"T_88af4_row5_col26\" class=\"data row5 col26\" >0.96</td>\n",
       "      <td id=\"T_88af4_row5_col27\" class=\"data row5 col27\" >0.91</td>\n",
       "      <td id=\"T_88af4_row5_col28\" class=\"data row5 col28\" >0.92</td>\n",
       "      <td id=\"T_88af4_row5_col29\" class=\"data row5 col29\" >0.96</td>\n",
       "      <td id=\"T_88af4_row5_col30\" class=\"data row5 col30\" >0.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_88af4_level0_row6\" class=\"row_heading level0 row6\" >Average</th>\n",
       "      <td id=\"T_88af4_row6_col0\" class=\"data row6 col0\" >0.46</td>\n",
       "      <td id=\"T_88af4_row6_col1\" class=\"data row6 col1\" >0.64</td>\n",
       "      <td id=\"T_88af4_row6_col2\" class=\"data row6 col2\" >0.70</td>\n",
       "      <td id=\"T_88af4_row6_col3\" class=\"data row6 col3\" >0.80</td>\n",
       "      <td id=\"T_88af4_row6_col4\" class=\"data row6 col4\" >0.60</td>\n",
       "      <td id=\"T_88af4_row6_col5\" class=\"data row6 col5\" >0.62</td>\n",
       "      <td id=\"T_88af4_row6_col6\" class=\"data row6 col6\" >0.44</td>\n",
       "      <td id=\"T_88af4_row6_col7\" class=\"data row6 col7\" >0.63</td>\n",
       "      <td id=\"T_88af4_row6_col8\" class=\"data row6 col8\" >0.66</td>\n",
       "      <td id=\"T_88af4_row6_col9\" class=\"data row6 col9\" >0.53</td>\n",
       "      <td id=\"T_88af4_row6_col10\" class=\"data row6 col10\" >0.59</td>\n",
       "      <td id=\"T_88af4_row6_col11\" class=\"data row6 col11\" >0.65</td>\n",
       "      <td id=\"T_88af4_row6_col12\" class=\"data row6 col12\" >0.66</td>\n",
       "      <td id=\"T_88af4_row6_col13\" class=\"data row6 col13\" >0.44</td>\n",
       "      <td id=\"T_88af4_row6_col14\" class=\"data row6 col14\" >0.45</td>\n",
       "      <td id=\"T_88af4_row6_col15\" class=\"data row6 col15\" >0.44</td>\n",
       "      <td id=\"T_88af4_row6_col16\" class=\"data row6 col16\" >0.44</td>\n",
       "      <td id=\"T_88af4_row6_col17\" class=\"data row6 col17\" >0.61</td>\n",
       "      <td id=\"T_88af4_row6_col18\" class=\"data row6 col18\" >0.68</td>\n",
       "      <td id=\"T_88af4_row6_col19\" class=\"data row6 col19\" >0.82</td>\n",
       "      <td id=\"T_88af4_row6_col20\" class=\"data row6 col20\" >0.63</td>\n",
       "      <td id=\"T_88af4_row6_col21\" class=\"data row6 col21\" >0.58</td>\n",
       "      <td id=\"T_88af4_row6_col22\" class=\"data row6 col22\" >0.63</td>\n",
       "      <td id=\"T_88af4_row6_col23\" class=\"data row6 col23\" >0.65</td>\n",
       "      <td id=\"T_88af4_row6_col24\" class=\"data row6 col24\" >0.66</td>\n",
       "      <td id=\"T_88af4_row6_col25\" class=\"data row6 col25\" >0.66</td>\n",
       "      <td id=\"T_88af4_row6_col26\" class=\"data row6 col26\" >0.64</td>\n",
       "      <td id=\"T_88af4_row6_col27\" class=\"data row6 col27\" >0.65</td>\n",
       "      <td id=\"T_88af4_row6_col28\" class=\"data row6 col28\" >0.66</td>\n",
       "      <td id=\"T_88af4_row6_col29\" class=\"data row6 col29\" >0.66</td>\n",
       "      <td id=\"T_88af4_row6_col30\" class=\"data row6 col30\" >0.64</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x7f047b714a30>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval = ts.evaluate()\n",
    "df = evaluation_as_table(eval)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading commonsense_qa...\n",
      "Loading med_qa...\n",
      "Loading medmc_qa...\n",
      "Loading open_book_qa...\n",
      "Loading strategy_qa...\n",
      "Loading worldtree...\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "| Name           |   Train | Valid   |   Test |\n",
       "|----------------|---------|---------|--------|\n",
       "| commonsense_qa |    9741 | 1221    |   1140 |\n",
       "| med_qa         |   10178 | 1272    |   1273 |\n",
       "| medmc_qa       |  182822 | 4183    |   6150 |\n",
       "| open_book_qa   |    4957 | 500     |    500 |\n",
       "| strategy_qa    |    2290 | -       |    490 |\n",
       "| worldtree      |    2207 | 496     |   1664 |\n",
       "\n",
       "Not loaded: ['aqua', 'asdiv', 'entailment_bank', 'gsm8k', 'mawps', 'pubmed_qa', 'qed', 'svamp']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "coll = Collection([\"commonsense_qa\", \"med_qa\", \"medmc_qa\", \"open_book_qa\", \"strategy_qa\", \"worldtree\"], verbose=False)\n",
    "coll"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Confidence correlation, p vlaue computation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.stats import ttest_ind"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6404205047932837"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len = 100\n",
    "accuracy_increase = 0.03\n",
    "arr1 = np.zeros(len)\n",
    "arr1[0:int(len*0.7)] = 1\n",
    "arr2 = np.zeros(len)\n",
    "arr2[0:int(len*(0.7+accuracy_increase))] = 1\n",
    "ttest_ind(arr1, arr2).pvalue"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.04619672569754267"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len = 1800\n",
    "accuracy_increase = 0.03\n",
    "arr1 = np.zeros(len)\n",
    "arr1[0:int(len*0.7)] = 1\n",
    "arr2 = np.zeros(len)\n",
    "arr2[0:int(len*(0.7+accuracy_increase))] = 1\n",
    "ttest_ind(arr1, arr2).pvalue"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Krippendorff's alpha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import krippendorff\n",
    "from sklearn import metrics\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*    *    *    *    *    3    4    1    2    1    1    3    3    *    3\n",
      "1    *    2    1    3    3    4    3    *    *    *    *    *    *    *\n",
      "*    *    2    1    3    4    4    *    2    1    1    3    3    *    4\n",
      "\n",
      "reliability_data:  [[nan, nan, nan, nan, nan, 3, 4, 1, 2, 1, 1, 3, 3, nan, 3], [1, nan, 2, 1, 3, 3, 4, 3, nan, nan, nan, nan, nan, nan, nan], [nan, nan, 2, 1, 3, 4, 4, nan, 2, 1, 1, 3, 3, nan, 4]]\n",
      "Krippendorff's alpha for nominal metric:  0.691358024691358\n",
      "Krippendorff's alpha for interval metric:  0.8108448928121059\n"
     ]
    }
   ],
   "source": [
    "reliability_data_str = (\n",
    "    \"*    *    *    *    *    3    4    1    2    1    1    3    3    *    3\",  # coder A\n",
    "    \"1    *    2    1    3    3    4    3    *    *    *    *    *    *    *\",  # coder B\n",
    "    \"*    *    2    1    3    4    4    *    2    1    1    3    3    *    4\",  # coder C\n",
    ")\n",
    "print('\\n'.join(reliability_data_str))\n",
    "print('')\n",
    "\n",
    "reliability_data = [[np.nan if v == '*' else int(v) for v in coder.split()] for coder in reliability_data_str]\n",
    "print(\"reliability_data: \", reliability_data)\n",
    "\n",
    "print(\"Krippendorff's alpha for nominal metric: \", krippendorff.alpha(reliability_data=reliability_data,\n",
    "                                                                        level_of_measurement='nominal'))\n",
    "print(\"Krippendorff's alpha for interval metric: \", krippendorff.alpha(reliability_data=reliability_data))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tryout with more data, Krippendorff's alpha gets smaller ???"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*    *    *    *    *    3    4    1    2    1    1    3    3    *    3\n",
      "1    *    2    1    3    3    4    3    *    *    *    *    *    *    *\n",
      "*    *    2    1    3    4    4    *    2    1    1    3    3    *    4\n",
      "\n",
      "reliability_data:  [[nan, nan, nan, nan, nan, 3, 4, 1, 2, 1, 1, 3, 3, nan, 3, nan, nan, nan, nan, nan, 3, 4, 1, 2, 1, 1, 3, 3, nan, 3, nan, nan, nan, nan, nan, 3, 4, 1, 2, 1, 1, 3, 3, nan, 3], [1, nan, 2, 1, 3, 3, 4, 3, nan, nan, nan, nan, nan, nan, nan, 1, nan, 2, 1, 3, 3, 4, 3, nan, nan, nan, nan, nan, nan, nan, 1, nan, 2, 1, 3, 3, 4, 3, nan, nan, nan, nan, nan, nan, nan], [nan, nan, 2, 1, 3, 4, 4, nan, 2, 1, 1, 3, 3, nan, 4, nan, nan, 2, 1, 3, 4, 4, nan, 2, 1, 1, 3, 3, nan, 4, nan, nan, 2, 1, 3, 4, 4, nan, 2, 1, 1, 3, 3, nan, 4]]\n",
      "Krippendorff's alpha for nominal metric:  0.6831275720164609\n",
      "Krippendorff's alpha for interval metric:  0.8058007566204288\n"
     ]
    }
   ],
   "source": [
    "reliability_data_str = (\n",
    "    \"*    *    *    *    *    3    4    1    2    1    1    3    3    *    3\",  # coder A\n",
    "    \"1    *    2    1    3    3    4    3    *    *    *    *    *    *    *\",  # coder B\n",
    "    \"*    *    2    1    3    4    4    *    2    1    1    3    3    *    4\",  # coder C\n",
    ")\n",
    "print('\\n'.join(reliability_data_str))\n",
    "print('')\n",
    "\n",
    "reliability_data = [[np.nan if v == '*' else int(v) for v in coder.split()]*3 for coder in reliability_data_str]\n",
    "print(\"reliability_data: \", reliability_data)\n",
    "\n",
    "print(\"Krippendorff's alpha for nominal metric: \", krippendorff.alpha(reliability_data=reliability_data,\n",
    "                                                                        level_of_measurement='nominal'))\n",
    "print(\"Krippendorff's alpha for interval metric: \", krippendorff.alpha(reliability_data=reliability_data))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.array([1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7,8])\n",
    "arr2 = np.array([1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7,8])\n",
    "reliability_data = np.array([arr1, arr2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Krippendorff's alpha for nominal metric:  1.0\n",
      "Cohen's kappa:  1.0\n"
     ]
    }
   ],
   "source": [
    "print(\"Krippendorff's alpha for nominal metric: \", krippendorff.alpha(reliability_data=reliability_data,\n",
    "                                                                        level_of_measurement='nominal'))\n",
    "print(\"Cohen's kappa: \", metrics.cohen_kappa_score(arr1, arr2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.array([1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,1,2,3])\n",
    "arr2 = np.array([1,1,2,2,2,3,3,3,4,4,4,5,5,5,5,2,3,4])\n",
    "reliability_data = np.array([arr1, arr2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Krippendorff's alpha for nominal metric:  0.5261121856866537\n",
      "Cohen's kappa:  0.5153846153846153\n"
     ]
    }
   ],
   "source": [
    "print(\"Krippendorff's alpha for nominal metric: \", krippendorff.alpha(reliability_data=reliability_data,\n",
    "                                                                        level_of_measurement='nominal'))\n",
    "print(\"Cohen's kappa: \", metrics.cohen_kappa_score(arr1, arr2))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "More classes makes better alpha and kappa:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.array([1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7,8])\n",
    "arr2 = np.array([1,1,2,2,2,3,3,3,4,4,4,5,5,5,5,9,10,11])\n",
    "reliability_data = np.array([arr1, arr2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Krippendorff's alpha for nominal metric:  0.5577617328519856\n",
      "Cohen's kappa:  0.5483870967741935\n"
     ]
    }
   ],
   "source": [
    "print(\"Krippendorff's alpha for nominal metric: \", krippendorff.alpha(reliability_data=reliability_data,\n",
    "                                                                        level_of_measurement='nominal'))\n",
    "print(\"Cohen's kappa: \", metrics.cohen_kappa_score(arr1, arr2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "More data let's Krippendorf's alpha approach Cohen's kappa:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.array([1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7,8])\n",
    "arr2 = np.array([1,1,2,2,2,3,3,3,4,4,4,5,5,5,5,9,10,11])\n",
    "arr1 = np.concatenate([arr1]*2)\n",
    "arr2 = np.concatenate([arr2]*2)\n",
    "reliability_data = np.array([arr1, arr2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Krippendorff's alpha for nominal metric:  0.5514440433212996\n",
      "Cohen's kappa:  0.5483870967741935\n"
     ]
    }
   ],
   "source": [
    "print(\"Krippendorff's alpha for nominal metric: \", krippendorff.alpha(reliability_data=reliability_data,\n",
    "                                                                        level_of_measurement='nominal'))\n",
    "print(\"Cohen's kappa: \", metrics.cohen_kappa_score(arr1, arr2))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Even more data let's Krippendorf's alpha again differ from Cohen's kappa to the other side:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.array([1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7,8])\n",
    "arr2 = np.array([1,1,2,2,2,3,3,3,4,4,4,5,5,5,5,9,10,11])\n",
    "arr1 = np.concatenate([arr1]*100)\n",
    "arr2 = np.concatenate([arr2]*100)\n",
    "reliability_data = np.array([arr1, arr2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Krippendorff's alpha for nominal metric:  0.5452527075812275\n",
      "Cohen's kappa:  0.5483870967741935\n"
     ]
    }
   ],
   "source": [
    "print(\"Krippendorff's alpha for nominal metric: \", krippendorff.alpha(reliability_data=reliability_data,\n",
    "                                                                        level_of_measurement='nominal'))\n",
    "print(\"Cohen's kappa: \", metrics.cohen_kappa_score(arr1, arr2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.array([1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7,8])\n",
    "arr2 = np.array([1,1,2,2,2,3,3,3,4,4,4,5,5,5,5,9,10,11])\n",
    "arr1 = np.concatenate([arr1]*10000)\n",
    "arr2 = np.concatenate([arr2]*10000)\n",
    "reliability_data = np.array([arr1, arr2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Krippendorff's alpha for nominal metric:  0.5451276173285197\n",
      "Cohen's kappa:  0.5483870967741935\n"
     ]
    }
   ],
   "source": [
    "print(\"Krippendorff's alpha for nominal metric: \", krippendorff.alpha(reliability_data=reliability_data,\n",
    "                                                                        level_of_measurement='nominal'))\n",
    "print(\"Cohen's kappa: \", metrics.cohen_kappa_score(arr1, arr2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Bootstrapping tryouts"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I will bootstrap confidence intervals for accuracy. Once for 70/100 and once for 700/1000. \n",
    "Then check if that matches the confidence intervals from the binomial distribution.\n",
    "Should be: \n",
    "\n",
    "1.96 * sqrt( (0.7 * (1 - 0.7)) / 100) = 0.089\n",
    "\n",
    "1.96 * sqrt( (0.7 * (1 - 0.7)) / 1000) = 0.028"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bootstrap CI (70/100): (0.61, 0.78)\n",
      "Binomial CI (70/100): (0.61, 0.7899999999999999)\n",
      "Bootstrap CI (700/1000): (0.672975, 0.728)\n",
      "Binomial CI (700/1000): (0.6709999999999999, 0.729)\n",
      "Margin of error (100): 0.08981848362113448\n",
      "Margin of error (1000): 0.0284030984225313\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from scipy.stats import binom\n",
    "\n",
    "def bootstrap_ci(successes, trials, alpha=0.05, n_bootstrap_samples=1000):\n",
    "    sample = np.array([1] * successes + [0] * (trials - successes))\n",
    "    bootstrap_samples = np.random.choice(sample, (n_bootstrap_samples, trials), replace=True)\n",
    "    bootstrap_means = np.mean(bootstrap_samples, axis=1)\n",
    "    ci_lower, ci_upper = np.percentile(bootstrap_means, [100 * alpha / 2, 100 * (1 - alpha / 2)])\n",
    "    return ci_lower, ci_upper\n",
    "\n",
    "def binomial_ci(successes, trials, alpha=0.05):\n",
    "    p = successes / trials\n",
    "    z = abs(binom.ppf(alpha / 2, trials, p) - successes) / trials\n",
    "    return p - z, p + z\n",
    "\n",
    "successes1, trials1 = 70, 100\n",
    "successes2, trials2 = 700, 1000\n",
    "\n",
    "bootstrap_ci1 = bootstrap_ci(successes1, trials1)\n",
    "binomial_ci1 = binomial_ci(successes1, trials1)\n",
    "print(f\"Bootstrap CI (70/100): {bootstrap_ci1}\")\n",
    "print(f\"Binomial CI (70/100): {binomial_ci1}\")\n",
    "\n",
    "bootstrap_ci2 = bootstrap_ci(successes2, trials2)\n",
    "binomial_ci2 = binomial_ci(successes2, trials2)\n",
    "print(f\"Bootstrap CI (700/1000): {bootstrap_ci2}\")\n",
    "print(f\"Binomial CI (700/1000): {binomial_ci2}\")\n",
    "\n",
    "# Calculating the margin of error for the binomial distribution\n",
    "margin_of_error_100 = 1.96 * np.sqrt((0.7 * (1 - 0.7)) / 100)\n",
    "margin_of_error_1000 = 1.96 * np.sqrt((0.7 * (1 - 0.7)) / 1000)\n",
    "print(f\"Margin of error (100): {margin_of_error_100}\")\n",
    "print(f\"Margin of error (1000): {margin_of_error_1000}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
